import java.io.*;
public class prime_palindrome {
   public static void main (String[] args) throws IOException {
      int biggest = 0;
      for (int i = 0; i<1000;i++) {

        if (isPrime(i)) {
           if (isPl(i))  biggest = i;
        }
      }
      System.out.print(biggest);
 }
   static boolean isPrime (int n) {
      if (n%2 == 0) return false;
      //if not then check the odds
      for (int i = 3;i*i<=n;i+=2) {
        if (n%i == 0) return false;
        }

      return true;
   }
   static boolean isPl (int p) {
     //check to see if the prime is a palindrome
     String pr = Integer.toString(p);
     for (int i = 0;i<pr.length();i++) {
     if (pr.charAt(i) != pr.charAt(pr.length()-1-i)) return false;
     }
     return true;
   }
 }